package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmpMapper {
    @Select("select * from emp where username = #{username}")
     Emp selectByUsername(String username);

    @Select("select count(*) from emp left join dept on emp.dept_id = dept.id ")
    public Long count();
    @Select("select emp.*,dept.name as deptName from emp left join dept on emp.dept_id = dept.id limit #{start},#{pageSize}")
    public List<Emp> list(Integer start, Integer pageSize);



     public Page<Emp> pageEmp(EmpQueryParam param);

     @Insert("insert into emp(username,password,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time)" +
             "values (#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
     @Options(useGeneratedKeys = true,keyProperty = "id")//获取数据库自动生成的id，并将其值赋值给emp对象的id属性。
     void insertEmp(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp selectById(Integer id);

    void update(Emp emp);


    @Select("select * from emp")
    List<Emp> selectEmps();
}
